<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员登录 - 留言板系统</title>
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --success-color: #4cc9f0;
            --error-color: #f72585;
            --background-color: #f8f9fa;
            --card-bg: #ffffff;
            --text-color: #343a40;
            --border-color: #e9ecef;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .login-container {
            width: 100%;
            max-width: 420px;
            background: var(--card-bg);
            border-radius: 16px;
            box-shadow: 0 15px 35px rgba(50, 50, 93, 0.1), 0 5px 15px rgba(0, 0, 0, 0.07);
            overflow: hidden;
            position: relative;
        }

        .login-header {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            text-align: center;
            padding: 40px 30px;
            position: relative;
        }

        .login-header::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='40' fill='none' stroke='rgba(255,255,255,0.1)' stroke-width='2'/%3E%3C/svg%3E");
            opacity: 0.3;
        }

        .login-header h1 {
            font-size: 28px;
            font-weight: 600;
            margin-bottom: 8px;
            position: relative;
            z-index: 1;
        }

        .login-header p {
            font-size: 16px;
            opacity: 0.9;
            position: relative;
            z-index: 1;
        }

        .login-form {
            padding: 40px 30px;
        }

        .form-group {
            margin-bottom: 25px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--text-color);
            font-size: 14px;
        }

        .input-group {
            position: relative;
        }

        .input-group input {
            width: 100%;
            padding: 14px 20px 14px 48px;
            border: 1px solid var(--border-color);
            border-radius: 10px;
            font-size: 16px;
            background-color: #fcfcfc;
            transition: all 0.3s;
        }

        .input-group input:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
            outline: none;
        }

        .input-icon {
            position: absolute;
            left: 16px;
            top: 50%;
            transform: translateY(-50%);
            color: #6c757d;
            font-size: 18px;
        }

        .error-container {
            background-color: rgba(247, 37, 133, 0.1);
            border-radius: 8px;
            padding: 12px 16px;
            margin-bottom: 20px;
            display: none;
        }

        .error-container p {
            color: var(--error-color);
            font-size: 14px;
            margin: 0;
        }

        .btn-login {
            width: 100%;
            padding: 14px;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
        }

        .btn-login:hover {
            transform: translateY(-2px);
            box-shadow: 0 7px 14px rgba(50, 50, 93, 0.1), 0 3px 6px rgba(0, 0, 0, 0.08);
        }

        .form-footer {
            text-align: center;
            margin-top: 25px;
            font-size: 14px;
            color: #6c757d;
        }

        .form-footer a {
            color: var(--primary-color);
            text-decoration: none;
            transition: all 0.3s;
        }

        .form-footer a:hover {
            text-decoration: underline;
        }

        .login-decoration {
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background: linear-gradient(to right, var(--success-color), #4895ef);
            opacity: 0.1;
            z-index: 0;
        }

        .decoration-1 {
            top: -80px;
            right: -80px;
            width: 250px;
            height: 250px;
        }

        .decoration-2 {
            bottom: -100px;
            left: -100px;
            width: 300px;
            height: 300px;
        }

        @media (max-width: 480px) {
            .login-container {
                max-width: 100%;
            }

            .login-header {
                padding: 30px 20px;
            }

            .login-form {
                padding: 30px 20px;
            }
        }

        /* 添加摇动动画 */
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
            20%, 40%, 60%, 80% { transform: translateX(5px); }
        }
    </style>
</head>
<body>
<div class="login-decoration decoration-1"></div>
<div class="login-decoration decoration-2"></div>

<div class="login-container">
    <div class="login-header">
        <h1>管理员登录</h1>
        <p>欢迎回来，请登录您的账户</p>
    </div>

    <div class="login-form">
        <!-- 错误消息容器 -->
        <div class="error-container" id="errorContainer">
            <p id="errorMessage"></p>
        </div>

        <form action="AdminLoginServlet" method="post" id="loginForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <div class="input-group">
                    <div class="input-icon">👤</div>
                    <input type="text" id="username" name="username" placeholder="请输入管理员用户名" required>
                </div>
            </div>

            <div class="form-group">
                <label for="password">密码</label>
                <div class="input-group">
                    <div class="input-icon">🔒</div>
                    <input type="password" id="password" name="password" placeholder="请输入您的密码" required>
                </div>
            </div>

            <button type="submit" class="btn-login">登 录</button>
        </form>

        <div class="form-footer">
            <a href="${pageContext.request.contextPath}/">返回首页</a>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const errorContainer = document.getElementById('errorContainer');
        const errorMessage = document.getElementById('errorMessage');
        const loginForm = document.getElementById('loginForm');

        // 检查是否有服务器返回的错误消息
        const serverError = '<%= request.getAttribute("error") != null ? request.getAttribute("error") : "" %>';

        if (serverError && serverError.trim() !== "") {
            errorMessage.textContent = serverError;
            errorContainer.style.display = 'block';
        }

        // 表单提交验证
        loginForm.addEventListener('submit', function(e) {
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value.trim();

            // 隐藏之前的错误消息
            errorContainer.style.display = 'none';

            // 客户端验证
            if (!username) {
                e.preventDefault();
                showError("请输入用户名");
                return;
            }

            if (!password) {
                e.preventDefault();
                showError("请输入密码");
                return;
            }

            if (password.length < 6) {
                e.preventDefault();
                showError("密码长度至少需要6位");
                return;
            }
        });

        function showError(message) {
            errorMessage.textContent = message;
            errorContainer.style.display = 'block';

            // 添加动画效果
            errorContainer.style.animation = 'shake 0.5s';
            setTimeout(() => {
                errorContainer.style.animation = '';
            }, 500);
        }
    });
</script>
</body>
</html>